import { queryPage } from './service';
import { routerRedux } from 'dva/router';
import { queryDictList } from '@/services/dict';

import assgin from 'lodash/assign';

function setList(list, index) {
  list[index].status = list[index].status === 'lock' ? 'normal' : 'lock';
  return list;
}

export default {
  namespace: 'patrol_user',

  state: {
    list: { data: [] },
    details: {},
    cond: {}
  },

  effects: {
    *queryPage({ payload }, { call, put, select }) {
      const cond = yield select(state => state.patrol_user.cond);
      const params = { ...payload, ...cond };
      const { list = [], total } = yield call(queryPage, params);
      yield put({ type: 'setPage', payload: { list, total } })
    }
  },

  reducers: {
    setPage(state, action) {
      return {
        ...state,
        list: {
          data: action.payload.list,
          dataCnt: action.payload.total
        }
      }
    }
  }
}
